<<<<<<< .mine
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;
using System.Drawing;
using System.Globalization;

namespace LogicUniversity.clerks
{
    public partial class order : System.Web.UI.Page
    {
        protected void Page_PreInit(Object sender, EventArgs e)
        {
            //(Session["Role"]
            if (Session["Role"] as string != "Clerk")
            {
                Response.Redirect("~/Login.aspx");
            }

        }
        private OrderControl orderControl = new OrderControl();
        private List<Catelogue> catList = null;
        private string supName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                catList = orderControl.getCatelogueUnderReorderLevel();
                OrderView.DataSource = catList;
                OrderView.DataBind();

                

                ddlSupplier.DataSource = orderControl.getSupplierNames();
                ddlSupplier.DataBind();


            }
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            supName = ddlSupplier.Items[ddlSupplier.SelectedIndex].Value.ToString();
            
            List<Catelogue> supCats = orderControl.getStationeryItemsSupplierdBy(supName.Trim());

            int count = 0;
            bool isFound = true;
            foreach (GridViewRow row in OrderView.Rows)
            {
                for (int i = 0; i < supCats.Count; i++)
                {
                    if (row.Cells[0].Text.Trim()!=supCats[i].Item_Code)
                    {
                        isFound = false;
                    }
                    else
                    {
                        isFound = true;
                        count++;
                        break;
                    }
                }
                if (!isFound)
                {
                    for (int j = 0; j < row.Cells.Count; j++)
                    {
                        row.Cells[j].ForeColor = ColorTranslator.FromHtml("#F5F5FF");
                    }
                    ((CheckBox)row.Cells[6].FindControl("chkChoose")).Enabled=false;
                }
                if (count > supCats.Count)
                    break;
            }

        }

        protected void OrderView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            OrderView.PageIndex = e.NewPageIndex;
            OrderView.DataBind();
        }

        protected void btnDate_Click(object sender, EventArgs e)
        {
            //date.Visible = true;
        }

        protected void btnPurchase_Click(object sender, EventArgs e)
        {
            //to retrieve from session;
            string clerkName="Sun Zhongwen";
            string empID="A0102918";
            string expectedDeliveryDate = txtDate.Text.Trim();
            DateTime deliveryDate;
            try
            {
                deliveryDate = DateTime.Parse(expectedDeliveryDate);
            }
            catch (FormatException fe)
            {
                return;
            }

            string supName = ddlSupplier.Items[ddlSupplier.SelectedIndex].Value.ToString();
            string supCode = orderControl.getSupplierIDOf(supName);

            Purchse_Order purchase = new Purchse_Order();
            purchase.Supplier_ID=supCode;
            purchase.Order_Datee = System.DateTime.Today;
            purchase.Expected_Deliver_Date=deliveryDate;
            purchase.IsDelievered = false ;

            int totalQty = 0;
            decimal totalPrice = 0;
            decimal totalAmt = 0;
            Purchase_Order_Detail purchaseDetail;

            foreach (GridViewRow row in OrderView.Rows)
            {
                CheckBox chk = (CheckBox)row.Cells[6].FindControl("chkChoose");

                if (chk.Checked)
                {
                    purchaseDetail = new Purchase_Order_Detail();
                    string itemCode = row.Cells[0].Text.Trim();
                    purchaseDetail.OnHand_Quantity=orderControl.getCurrentBalanceOf(itemCode);

                    purchaseDetail.Quantity = orderControl.getReorderQtyOf(itemCode);
                    totalQty += purchaseDetail.Quantity;

                    purchaseDetail.Price = orderControl.getUnitPriceOf(itemCode) ;
                    totalPrice += purchaseDetail.Price;

                    purchaseDetail.Amount = purchaseDetail.Price * purchaseDetail.Quantity;
                    totalAmt += purchaseDetail.Amount;

                    purchaseDetail.Item_Code = itemCode;
                    purchase.Purchase_Order_Detail.Add(purchaseDetail);
                }

            }

            orderControl.orderStationeryItems(purchase);

            string deliverTo = "Logic University, Singapore.";
            string url = "OrderDetails.aspx?supname="+supName+"&deliver="+deliverTo+"&expectedDate="+expectedDeliveryDate+"&orderby="+clerkName+"_"+empID+
                "&totalQty="+totalQty+"&totalPrice="+totalPrice+"&totalAmt="+totalAmt;

            Session["purchase"] = purchase;

            Response.Redirect(url);
        }
    }
}=======
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;
using System.Drawing;
using System.Globalization;

namespace LogicUniversity.clerks
{
    public partial class order : System.Web.UI.Page
    {
        private OrderControl orderControl = new OrderControl();
        private List<Catelogue> catList = null;
        private string supName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                catList = orderControl.getCatelogueUnderReorderLevel();
                OrderView.DataSource = catList;
                OrderView.DataBind();

                

                ddlSupplier.DataSource = orderControl.getSupplierNames();
                ddlSupplier.DataBind();


            }
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            supName = ddlSupplier.Items[ddlSupplier.SelectedIndex].Value.ToString();

            List<Catelogue> supCats = orderControl.getStationeryItemsSupplierdBy(supName.Trim());

            int count = 0;
            bool isFound = true;
            foreach (GridViewRow row in OrderView.Rows)
            {
                for (int i = 0; i < supCats.Count; i++)
                {
                    if (row.Cells[0].Text.Trim()!=supCats[i].Item_Code)
                    {
                        isFound = false;
                    }
                    else
                    {
                        isFound = true;
                        count++;
                        break;
                    }
                }
                if (!isFound)
                {
                    for (int j = 0; j < row.Cells.Count; j++)
                    {
                        row.Cells[j].ForeColor = ColorTranslator.FromHtml("#E0F0FF");
                    }
                    ((CheckBox)row.Cells[6].FindControl("chkChoose")).Enabled=false;
                }
                if (count > supCats.Count)
                    break;
            }

        }

        protected void OrderView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            OrderView.PageIndex = e.NewPageIndex;
            OrderView.DataBind();
        }

        protected void btnDate_Click(object sender, EventArgs e)
        {
            date.Visible = true;
        }

        protected void date_SelectionChanged(object sender, EventArgs e)
        {
            txtDate.Text = date.SelectedDate.ToShortDateString();
            date.Visible = false;
        }

        protected void btnPurchase_Click(object sender, EventArgs e)
        {
            string expectedDeliveryDate = txtDate.Text.Trim();
            DateTime deliveryDate = DateTime.Parse(expectedDeliveryDate);

            string supCode = orderControl.getSupplierIDOf(supName = ddlSupplier.Items[ddlSupplier.SelectedIndex].Value.ToString());

            Purchse_Order purchase = new Purchse_Order();
            purchase.Supplier_ID=supCode;
            purchase.Order_Datee = System.DateTime.Today;
            purchase.Expected_Deliver_Date=deliveryDate;
            purchase.IsDelievered = false ;

            Purchase_Order_Detail purchaseDetail;

            foreach (GridViewRow row in OrderView.Rows)
            {
                CheckBox chk = (CheckBox)row.Cells[6].FindControl("chkChoose");

                if (chk.Checked)
                {
                    purchaseDetail = new Purchase_Order_Detail();
                    string itemCode = row.Cells[0].Text.Trim();
                    purchaseDetail.OnHand_Quantity=orderControl.getCurrentBalanceOf(itemCode);
                    purchaseDetail.Quantity = orderControl.getReorderQtyOf(itemCode);
                    purchaseDetail.Price = orderControl.getUnitPriceOf(itemCode) ;
                    purchaseDetail.Amount = purchaseDetail.Price * purchaseDetail.Quantity;
                    purchaseDetail.Item_Code = itemCode;
                    purchase.Purchase_Order_Detail.Add(purchaseDetail);
                }

            }

            orderControl.orderStationeryItems(purchase);
        }
    }
}>>>>>>> .r28
